package com.jiayuge.server.controller;


import com.jiayuge.server.common.entity.RespBean;
import com.jiayuge.server.pojo.Admin;
import com.jiayuge.server.service.IAdminService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Jiayu.Yang
 * @since 2021-11-16
 */
@RestController
@RequestMapping("/system/admin")
@Api(tags = "AdminController 操作员")
public class AdminController {
    @Autowired
    private IAdminService adminService;

    @ApiOperation(value = "获取所有操作员(模糊查询)")
    @GetMapping("/")
    public List<Admin> getAllAdmin(String keywords){
        return adminService.getAllAdmin(keywords);
    }

    @ApiOperation(value = "更新操作员信息")
    @PutMapping("/")
    public RespBean updateAdmin(@RequestBody Admin admin){
        if (adminService.updateById(admin)) {
            return RespBean.success("更新成功");
        }
        return RespBean.error("更新失败");
    }

    @ApiOperation(value = "删除操作员")
    @DeleteMapping("/{id}")
    public RespBean deleteAdminById(@PathVariable Integer id){
        if (adminService.removeById(id)) {
            return RespBean.success("删除成功");
        }
        return RespBean.error("删除失败");
    }

    @ApiOperation(value = "更新操作员角色")
    @PutMapping("/role")
    public RespBean updateAdminRole(Integer aid ,Integer[] rids){
       return adminService.updateAdminRole(aid,rids);
    }


}
